﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

//WB Added
using System.IO;
using System.Xml;


namespace USTF.Package.Install
{
    public partial class Installer : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnContinue_Click(object sender, EventArgs e)
        {
            string configFilePath = Server.MapPath("~/SUMO/config/app.config");

            //Check if XML file exists
            if (!File.Exists(configFilePath))
            {
                //Throw error saying file does not exist (it should though from package install)

                return;
            }
            else
            {
                string sendStatsVal = string.Empty;

                //Set the checkbox value to human readable values :)
                if (chkSendStats.Checked)
                {
                    sendStatsVal = "true";
                }
                else
                {
                    sendStatsVal = "false";
                }

                
                //Load the XML doc
                XmlDocument configFile = new XmlDocument();
                configFile.Load(configFilePath);

                //Select the root node <config>
                XmlNode rootNode = configFile.DocumentElement;

                //<sendAnonymousStats value="true" />
                rootNode.SelectSingleNode("sendAnonymousStats").Attributes.GetNamedItem("value").Value = sendStatsVal;

                //Save the changes
                configFile.Save(configFilePath);

                //Hide setup panel
                pnlInstall.Visible = false;

                //Show done panel
                pnlDone.Visible = true;
            }

        }
    }
}